unit HndRailDlg;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, HndRailObj;

type
  THandRailDlg = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Edit_H: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit_H2: TEdit;
    Edit_H140: TEdit;
    Label4: TLabel;
    Edit_L: TEdit;
    CheckBox_vert: TCheckBox;
    Bevel1: TBevel;
    cb1: TCheckBox;
    cb2: TCheckBox;
    Panel1: TPanel;
    PaintBox1: TPaintBox;
    procedure PaintBoxPaint(Sender: TObject);
    procedure CheckBox_vertClick(Sender: TObject);
    procedure cb1Click(Sender: TObject);
    procedure cb2Click(Sender: TObject);
  private
    fparams: THandRail_Params;
  public
    constructor Create(aOwner: TComponent); override;
	destructor Destroy; override;
	procedure SetData (dataBuf: THandRail_Params);
	procedure GetData (var dataBuf: THandRail_Params);
  end;

var
  HandRailDlg: THandRailDlg;

implementation

uses Global, Dialogs;

{$R *.dfm}

constructor THandRailDlg.Create (aOwner: TComponent);
begin
inherited Create(aOwner);
  fparams:= THandRail_Params.Create;
end;

destructor THandRailDlg.Destroy;
begin
  fparams.Free;
inherited Destroy;
end;

procedure THandRailDlg.SetData(dataBuf: THandRail_Params);
begin
	fparams.CopyFrom(dataBuf);
	
	CheckBox_vert.checked:= (fparams.drawType = DT_VERTIC);
	
	cb1.checked:= (fparams.flags and HRP_ADDON1) <> 0;
	cb2.checked:= (fparams.flags and HRP_ADDON2) <> 0;
	
	cb1.enabled:= fparams.drawType <> DT_VERTIC;
	cb2.enabled:= cb1.enabled;
	
	Edit_H.text:= FloatToStr(fparams.H);
	Edit_H2.text:= FloatToStr(fparams.H2);
	Edit_H140.text:= FloatToStr(fparams.H140);
  Edit_L.Text:= FloatToStr(fparams.Lmax);
end;

procedure THandRailDlg.GetData(var dataBuf: THandRail_Params);
begin
  fparams.H:= StrToFloat(Edit_H.Text);
  fparams.H2:= StrToFloat(Edit_H2.Text);
  fparams.H140:= strToFloat(Edit_H140.Text);
  fparams.Lmax:= StrToFloat(Edit_L.Text);
  
  dataBuf.CopyFrom(fparams);
end;


procedure THandRailDlg.PaintBoxPaint(Sender: TObject);
begin
  iKompas.ksDrawSlide(Panel1.Handle , fparams.GetSlideID );
 //ikompas.ksDrawSlideFromFile( Panel1.Handle, 'c:\Users\vit\Desktop\km\Handrail\4001.rc' );
 // showmessage(inttostr(res));
end;

procedure THandRailDlg.CheckBox_vertClick(Sender: TObject);
begin
  if CheckBox_vert.Checked then
    fparams.drawType:= DT_VERTIC
  else fparams.drawType:= DT_PERPEND;

  cb1.Enabled:= not CheckBox_vert.Checked;
  cb2.Enabled:= not CheckBox_vert.Checked;

  Panel1.Repaint;
end;

procedure THandRailDlg.cb1Click(Sender: TObject);
begin
  if cb1.Checked then fparams.flags:= fparams.flags or HRP_ADDON1
  else fparams.flags:= fparams.flags and (not HRP_ADDON1);

  Panel1.Repaint;
end;

procedure THandRailDlg.cb2Click(Sender: TObject);
begin
  if cb2.Checked then fparams.flags:= fparams.flags or HRP_ADDON2
  else fparams.flags:= fparams.flags and (not HRP_ADDON2);

  Panel1.Repaint;
end;

end.
